from selenium import webdriver
from selenium.webdriver.common.by import By
import unittest
# 导入test_login中的test_login类
from selenium.webdriver import ActionChains
from test.login import login
from time import sleep


class test_adduser(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.driver = webdriver.Chrome()
        cls.driver.get("http://localhost:8080")
        cls.driver.implicitly_wait(5)

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()

    def add_user(self):
        # 打开后窗口最大化
        self.driver.maximize_window()
        # 导入test_login中的test_login类中的login方法
        login.login(self)
        self.driver.implicitly_wait(10)
        self.driver.find_element(By.XPATH, "//*[@id='fsLeftMenu']/li[1]/dl/dd[1]").click()
        self.driver.implicitly_wait(10)
        iframe = self.driver.find_element(By.XPATH, "/html/body/div[2]/form/div[4]/div/div/div/iframe")
        self.driver.switch_to.frame(iframe)
        self.driver.implicitly_wait(10)
        self.driver.find_element(By.ID, "table-button-add").click()
        self.driver.implicitly_wait(10)
        # iframe_2 = self.driver.find_element(By.XPATH, "/html/body/div[2]/form/div[4]/div/div/div[2]/iframe")
        self.driver.switch_to.frame(0)
        self.driver.implicitly_wait(10)
        self.driver.find_element(By.NAME, "name").send_keys("王逢基")
        self.driver.implicitly_wait(10)
        self.driver.find_element(By.NAME, "code").send_keys(f"100{+1}")
        sleep(3)
        self.driver.find_element(By.CSS_SELECTOR, "#orgIdSearch").click()
        self.driver.implicitly_wait(10)
        self.driver.find_element(By.CSS_SELECTOR, "#_treeDemo_1_span").click()
        self.driver.implicitly_wait(10)
        self.driver.find_element(By.CLASS_NAME, "layui-layer-btn0").click()
        self.driver.implicitly_wait(10)
        self.driver.find_element(By.CSS_SELECTOR, "#addForm > div:nth-child(2) > div:nth-child(2) > div > div > div > div > i").click()
        self.driver.implicitly_wait(10)
        self.driver.find_element(By.CSS_SELECTOR, "#addForm > div:nth-child(2) > div:nth-child(2) > div > div > div > dl > dd:nth-child(3)").click()
        self.driver.implicitly_wait(10)
        self.driver.find_element(By.CSS_SELECTOR, "#addForm > div:nth-child(3) > div:nth-child(1) > div > div > div > div > div > i").click()
        self.driver.implicitly_wait(10)
        self.driver.find_element(By.CSS_SELECTOR, "#addForm > div:nth-child(3) > div:nth-child(1) > div > div > div > div > dl > dd:nth-child(2)").click()
        sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#addForm > div:nth-child(3) > div:nth-child(2) > div > div > div > div > i").click()
        self.driver.implicitly_wait(10)
        self.driver.find_element(By.CSS_SELECTOR, "#addForm > div:nth-child(3) > div:nth-child(2) > div > div > div > dl > dd:nth-child(2)").click()
        self.driver.implicitly_wait(10)
        self.driver.find_element(By.CSS_SELECTOR, "#saveUser").click()

    def test_add_user(self):
        self.add_user()


if __name__ == "__main__":
    unittest.main()
